﻿var gulp = require('gulp'),
	less = require('gulp-less'),
	seajsCombo = require( 'gulp-seajs-combo' ),
	mainBowerFiles = require('main-bower-files'),
	autoprefixer = require('gulp-autoprefixer'),
	bowerNormalizer = require('gulp-bower-normalize'),
	flatten = require('gulp-flatten'),
	vinylPaths = require('vinyl-paths'),
	gulpCopy = require('gulp-copy'),
	replace = require('gulp-replace-path'),
	connect = require('gulp-connect');

gulp.task('connect', function() {
	connect.server({
		root: ['./src','./bower_components'],
		livereload: true,
		port:2017
	});
});

gulp.task('less', function() {
	gulp.src('./src/less/*.less')
	.pipe(less())
	.pipe(autoprefixer({
            browsers: ['>0.2%'],
            cascade: false
    }))
	.pipe(gulp.dest('./src/css'));
});

gulp.task('reload', function () {
	gulp.src(['src/*.html','src/css/*.css','src/js/*.js'])
	.pipe(connect.reload());
});

gulp.task('watch', function() {
	gulp.watch('src/less/*.less', ['less']);
	gulp.watch('bower_components/*', ['bower_components']);
	gulp.watch(['src/css/*.css','src/js/*.js','src/*.html'], ['reload']);
});

gulp.task('bower_components', function() {
	return gulp.src(
		mainBowerFiles({
			base:"./",
			paths: {
				bowerDirectory: './bower_components',
				bowerrc: '.bowerrc',
				bowerJson: 'bower.json'
			},
			dependencies: {
			},
			overrides:{
				"font-awesome": {
					"main": [
						"fonts/*",
						"less/**/*.less"
					]
				},
				"bootstrap": {
					"main": [
						"less/**/*.less"
					]
				},
				"iscroll": {
					"main": [
						"build/*.js"
					]
				}
			}
		})
	)
	.pipe(gulpCopy("./src/lib/",{prefix:1}))
});

gulp.task('default',['watch','connect','bower_components'], function() {
});


